function CoordinatesUtil(){
	"use strict";
}

// Precomputed constants for rendering optimization
CoordinatesUtil.TILE_x2x = Constants.TILE_WIDTH/2;
CoordinatesUtil.TILE_y2x = Constants.TILE_HEIGHT;
CoordinatesUtil.TILE_x2y = Constants.TILE_WIDTH/2/2;
CoordinatesUtil.TILE_y2y = - Constants.TILE_HEIGHT/2;

// Precomputed constants for rendering optimization (isometric to orthografic)
CoordinatesUtil.ISO_TO_ORTHO_1=CoordinatesUtil.TILE_y2x/CoordinatesUtil.TILE_y2y;
CoordinatesUtil.ISO_TO_ORTHO_2=CoordinatesUtil.TILE_x2x-CoordinatesUtil.ISO_TO_ORTHO_1*CoordinatesUtil.TILE_x2y;
CoordinatesUtil.ISO_TO_ORTHO_3=CoordinatesUtil.TILE_x2x/CoordinatesUtil.TILE_x2y;
CoordinatesUtil.ISO_TO_ORTHO_4=CoordinatesUtil.TILE_y2x-CoordinatesUtil.ISO_TO_ORTHO_3*CoordinatesUtil.TILE_y2y;

//Get canvas X for object in tile i,j
//ox,oy is the offset of the image in tiles
CoordinatesUtil.getX = function (i,j,offsetX,offsetY) {
	"use strict";
	return i*CoordinatesUtil.TILE_x2x + j*CoordinatesUtil.TILE_y2x - offsetX*Constants.TILE_WIDTH;
};

//Get canvas Y for object in tile i,j
//ox,oy is the offset of the image in tiles
CoordinatesUtil.getY = function (i,j,offsetX,offsetY) {
	"use strict";
	return i*CoordinatesUtil.TILE_x2y + j*CoordinatesUtil.TILE_y2y - offsetY*Constants.TILE_HEIGHT;
};

//Returns distance from a point in canvas to the object's position
CoordinatesUtil.computeDistance = function (xm,ym,obj) {
	"use strict";
	var xo,yo;
	xo = CoordinatesUtil.getX(obj.x,obj.y,0,0);
	yo = CoordinatesUtil.getY(obj.x,obj.y,0,0);
	//
	return Math.sqrt(Math.pow(xo-xm,2) + Math.pow(yo-ym,2));
};

//Returns distance from two points
CoordinatesUtil.computePointDistance = function (xm,ym,xo,yo) {
	"use strict";
	//
	return Math.sqrt(Math.pow(xo-xm,2) + Math.pow(yo-ym,2));
};

//Get Tile i for canvas coordinates
CoordinatesUtil.getTileX = function (x,y) {
	"use strict";
	return (x-CoordinatesUtil.ISO_TO_ORTHO_1*y) / CoordinatesUtil.ISO_TO_ORTHO_2;
};

//Get Tile j for canvas coordinates
CoordinatesUtil.getTileY = function (x,y) {
	"use strict";
	return (x-CoordinatesUtil.ISO_TO_ORTHO_3*y)/ CoordinatesUtil.ISO_TO_ORTHO_4;
};
